<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>
<body>
    <!-- 函数的传参:在括号内传参,与react不同的是,此时的括号作用仅仅是作为传参使用,,不传参可以不加括号 -->
    <div id="app">
        <div>
            {{count}}
        </div>
        <button @click="increment(2)">每次加2</button>
        <br>
        <button @click="decrement">点击减一</button>
        <br>
        <button @click="oddDecrement(2,$event)">点击减2</button>
    </div>
    <script>
        new Vue({
            data(){
                return{
                    count:1
                }
            },
            methods:{
                increment(n){
                   this.count+=2
                },
                //在不接收参数的情况下,函数默认会拥有一个event对象,和原生js中的event一致
                decrement(e){
                    alert(e)
                    this.count--
                },
                //在接收参数的情况下,dom传入$event,对应参数可以接收,$event的值为evnet对象
                oddDecrement(n,e){
                    alert(e)
                    this.count-=n
                }

            }
        }).$mount('#app')
    </script>
</body>
</html>